/*
 * blockPCB.c
 *
 *  Created on: Oct 2, 2013
 *      Author: Joseph DeLong
 */

#include <stdlib.h>
#include "mpx_pcb.h"

/*
 * BLOCK PCB
 * Written by Joseph DeLong
 * Debugged by Alex Newcomer
 * Calls find_PCB(), places the PCB in the blocked state and reinserts it to the correct queue if necessary
 * Parameters: Process Name
 * Error Checking:
 * 	Name must be valid
 * Should not change the suspended status
 * Should display a success or error message
 */
void blockPCB(char processName[9], struct MPX_Q *r, struct MPX_Q *b) {
	struct MPX_PCB *pcb;
	pcb = findPCB(processName);
	if(pcb == NULL) { //couldn't find PCB
		printf("Couldn't find PCB %s to set to BLOCKED state.\n", processName);
	}
	else { //PCB found!
		if((*pcb).pcb_state == -1) { //PCB already blocked
			printf("PCB %s is already in the BLOCKED state.\n", processName);
		}
		else {
			(*pcb).pcb_state = -1; //set state to BLOCKED
			removePCB(pcb,r,b); //remove from ready queue
			insertPCB(pcb,r,b); //add to blocked queue
			printf("PCB %s successfully BLOCKED.\n", processName);
		}
	}
}
